/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package embeddedpaint.user_interface;

import embeddedpaint.model.feature.AImageTool;
import embeddedpaint.model.feature.ToolListManager;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;

public class ToolBar extends JToolBar implements Observer
{
    private ArrayList<MyButton> m_buttonList;

    public ToolBar (ToolListManager toolListe)
    {
        this.m_buttonList = new ArrayList<>();

        ArrayList<AImageTool> list = toolListe.getM_toolList();

        for (AImageTool aImageTool : list)
        {
            AbstractButton buton;

            if (aImageTool.isToggleButton())
            {
                buton = new JToggleButton(aImageTool.getIcon());
            }
            else
            {
                buton = new JButton(aImageTool.getIcon());
            }
            
            MyButton button = new MyButton(buton, aImageTool);
            
            this.m_buttonList.add(button);
            
            button.addObserver(this);

            this.add(buton);
        }
    }

    @Override
    public void update (Observable o, Object arg)
    {
        for (MyButton myButton : m_buttonList)
        {
            if (myButton != o)
            {
                myButton.disable();
            }
        }
    }
}
